import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_yishop/constants/Constants.dart';
import 'package:flutter_yishop/utils/screen/ScreenAdapter.dart';

class SplashPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _SplashPageState();
  }

}

class _SplashPageState extends State<SplashPage>{


  int changeIndex=0;
  Timer timer;



  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    timer=Timer.periodic(Duration(milliseconds: 50), (sd){
      setState(() {
        changeIndex+=1;
      });
      if(changeIndex>=100){
        _openMain();
      }
    });

  }

  void _openMain(){
    timer?.cancel();
    timer=null;
    Navigator.of(context).pushReplacementNamed(Constants.TABS);
  }


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Container(
            width: double.infinity,
            height: double.infinity,
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Container(
                    width: ScreenAdapter.width(150),
                    height: ScreenAdapter.height(150),
                    child: AspectRatio(
                      aspectRatio: 1,
                      child: Image.asset("assets/images/ic_logo.png"),
                    ),
                  ),
                  SizedBox(height: ScreenAdapter.height(20),),
                  Stack(
                    children: [
                      Text("YiGo",style: TextStyle(
                          fontSize: 25,
                          color: Colors.yellow,
                          fontFamily: 'ZhanKu'
                      ),),
                      Container(
                        margin: EdgeInsets.only(top: ScreenAdapter.height(2),left: ScreenAdapter.width(2)),
                        child:Text("YiGo",style: TextStyle(
                            fontSize: 25,
                            color: Colors.cyanAccent,
                            fontFamily: 'ZhanKu'
                        ),),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenAdapter.height(4),left: ScreenAdapter.width(4)),
                        child:Text("YiGo",style: TextStyle(
                            fontSize: 25,
                            color: Colors.blueAccent,
                            fontFamily: 'ZhanKu'
                        ),),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenAdapter.height(6),left: ScreenAdapter.width(6)),
                        child:Text("YiGo",style: TextStyle(
                            fontSize: 25,
                            color: Colors.deepPurpleAccent,
                            fontFamily: 'ZhanKu'
                        ),),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenAdapter.height(8),left: ScreenAdapter.width(8)),
                        child:Text("YiGo",style: TextStyle(
                            fontSize: 25,
                            color: Colors.pinkAccent,
                            fontFamily: 'ZhanKu'
                        ),),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ),
          Container(
            alignment: Alignment.bottomRight,//设置内容的显示对其方式为 靠右下角显示
            child: Container(
              width: 60,
              height: 60,
              decoration: BoxDecoration(
//                color: Colors.green,//设置背景色，为了看清控件位置设置，在界面完成之后屏蔽此代码
                borderRadius: BorderRadius.all(Radius.circular(30)),//设置圆角
              ),
              alignment: Alignment.center,//居中显示
              margin: EdgeInsets.all(25),//设置外边距
              child: GestureDetector(
                child: Stack(
                  children: <Widget>[
                    Container(
                      alignment: Alignment.center,
                      child: CircularProgressIndicator(
                        value: changeIndex/100,
                        strokeWidth: 1,
                      ),
                    ),
                    Container(
                      alignment: Alignment.center,
                      child: Text("跳过"),
                    ),
                  ],
                ),
                onTap: (){
                  _openMain();
                },
              ),
            ),
          ),

        ],
      ),
    );

  }

}